import collections


class Solution(object):
    def spellchecker(self, wordlist, queries):
        w_s = set(wordlist)
        l_d = {}
        yuan_d = {}
        for word in wordlist:
            w = word.lower()
            if w not in l_d:
                l_d[w] = word
            t = ''
            for c in w:
                if c in {'a', 'e', 'i', 'o', 'u'}:
                    t += '*'
                else:
                    t += c
            if t not in yuan_d:
                yuan_d[t] = word
        for i, q in enumerate(queries):
            if q in w_s:
                continue
            w = q.lower()
            if w in l_d:
                queries[i] = l_d[w]
            else:
                t = ''
                for c in w:
                    if c in {'a', 'e', 'i', 'o', 'u'}:
                        t += '*'
                    else:
                        t += c
                if t in yuan_d:
                    queries[i] = yuan_d[t]
                else:
                    queries[i] = ''
        return queries


data = Solution()
wordlist = ["KiTe", "kite", "hare", "Hare"]
queries = ["kite", "Kite", "KiTe", "Hare", "HARE", "Hear", "hear", "keti", "keet", "keto"]
print(data.spellchecker(wordlist, queries))
